
const express = require('express');
const app = express()
var cors = require('cors')
app.use(express.json())
app.use(cors())


app.get("/hhhh",(req,res)=>{
    res.json({
        a:1
    })
})

app.post("/login", (req, res) => {
    let account = req.body.account
    let password = req.body.password
    if (account == 'admin' && password == "1") {
        res.json({
            id: "1",
            msg: "登录成功"
        })
    } else if (account == 'admin' && password == "2") {
        res.json({
            id: "2",
            msg: "登录成功"
        })
    } else if (account == 'admin' && password == "3") {
        res.json({
            id: "3",
            msg: "登录成功"
        })
    } else {
        res.json({
            msg: "登录错误"
        })
    }
})

app.get("/getroutes/:id", (req, res) => {
    let id = req.params.id
    if (id == '1') {
        res.json({
            msg:"获取成功",
            data: [
                {
                    path: "/page2",
                    Component: "Page2"
                },
                {
                    path: "/page3",
                    Component: "Page3"
                }
            ]
        })
    }else if (id == '2'){
        res.json({
            msg:"获取成功",
            data: [
                {
                    path: "/page1",
                    Component: "Page1",
                    children: [
                        {
                            path: "son1",
                            Component: "Page1Son1"
                        },
                        {
                            path: "son2",
                            Component: "Page1Son2"
                        }
                    ]
                },
                {
                    path: "/page3",
                    Component: "Page3"
                }
            ]
        })
    }else if (id == '3'){
        res.json({
            msg:"获取成功",
            data: [
                {
                    path: "/page1",
                    Component: "Page1",
                    children: [
                        {
                            path: "son1",
                            Component: "Page1Son1"
                        },
                        {
                            path: "son2",
                            Component: "Page1Son2"
                        }
                    ]
                },
                {
                    path: "/page2",
                    Component: "Page2"
                },
                {
                    path: "/page3",
                    Component: "Page3"
                }
            ]
        })
    }else{
        res.json({
            msg:"获取失败",
            data:[]
        })
    }
})



app.listen(8001, () => {
    console.log("端口8001开启成功")
})